package com.leetcode.partition18;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/1 16:46
 */
public class LC1763最长的美好子字符串 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String s = reader.readLine();
        writer.write(longestNiceSubstring(s));
        writer.flush();
    }

    public static String longestNiceSubstring(String s) {
        String ans = "";
        for (int i = 0; i < s.length(); i++) {
            for (int j = i + 2; j <= s.length(); j++) {
                String ss = s.substring(i, j);
                if (check(ss) && ss.length() > ans.length()) ans = ss;
            }
        }
        return ans;
    }

    private static boolean check(String s) {
        boolean[] cnt1 = new boolean[26], cnt2 = new boolean[26];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c >= 'a' && c <= 'z') cnt1[c - 'a'] = true;
            else if (c >= 'A' && c <= 'Z') cnt2[c - 'A'] = true;
        }
        for (int i = 0; i < 26; i++) {
            if (cnt1[i] != cnt2[i]) return false;
        }
        return true;
    }
}
